<?php
namespace app\web\api;
use app\src\user\enum\RegFromEnum;
use app\src\user\enum\RoleEnum;
use app\web\helper\WebApiHelper;

/**
 * Created by PhpStorm.
 * User: Gooraye
 * Date: 2017-06-03
 * Time: 13:53
 */
class UserApi
{

    /**
     * 注册接口
     * @param $nickname
     * @param $username
     * @param $password
     * @param $email
     * @param $country
     * @param string $code
     * @return array
     */
    public static function register($nickname, $username, $password, $email,$code = 'itboye',$invite_code,$wxopenid)
    {
        $data = [
            'api_ver' => '103',
            'nickname' => $nickname,
            'username' => $username,
            'password' => $password,
            'wxopenid' => $wxopenid,
            'invite_code' => $invite_code,
            'email' => $email,
            'country' => '+86',
            'code' => $code,
            'reg_from' => RegFromEnum::WEIXIN
        ];
        return WebApiHelper::callRemote('By_User_register', $data);
    }

    public static function login($username, $password, $device_token, $device_type, $country = '86')
    {

        $data = [
            'api_ver' => '104',
            'username' => $username,
            'password' => $password,
            'country' => $country,
            'device_token' => $device_token,
            'device_type' => $device_type,
            'role' => RoleEnum::ROLE_User
        ];
        return WebApiHelper::callRemote('By_User_login', $data);
    }

    public static function update($uid,$nickname,$sex,$sign,$head,$email = '')
    {

        $data = [
            'api_ver' => '100',
            's_id' => 'itboye',
            'uid' => $uid,
            'nickname' => $nickname,
            'sex' => $sex,
            'sign' => $sign,
            'head' => $head,
            'email' =>$email
        ];
        return WebApiHelper::callRemote('By_User_update', $data);
    }

    public static function updatePwd($mobile,$password,$code,$country = '+86')
    {

        $data = [
            'api_ver' => '101',
            'mobile'=>$mobile,
            's_id'=>'itboye',
            'password'=>$password,
            'code'=>$code,
            'country'=>$country
        ];
        return WebApiHelper::callRemote('By_User_updatePwd', $data);
    }
    public static function code($mobile,$code_type){
        $data=[
            'api_ver' => '101',
            'mobile'=>$mobile,
            'code_type'=>$code_type,
            'country' =>'+86'
        ];
        return WebApiHelper::callRemote('By_SecurityCode_send', $data);
    }

    public static function verify($country,$mobile,$code,$code_type){
        $data=[
            'api_ver' => '101',
            'mobile'=>$mobile,
            'code'=>$code,
            'code_type'=>$code_type,
            'country' =>$country
        ];
        return WebApiHelper::callRemote('By_SecurityCode_verify', $data);
    }
}